﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using PstBakup2013Server;
using System;

namespace Unit_Tests_PstBakup2013Server
{
    [TestClass]
    public class ClientMessageTest
    {
        [TestMethod]
        public void ClientMessageTestConstructor()
        {
            string xmlMsg =
        "<Message id=\"{0}\">" +
            "<Client id=\"{1}\" ClientVersion=\"{2}\" Date=\"{3}\"/>" +
            "<ComputerName>{4}</ComputerName>" +
            "<UserName>{5}</UserName>" +
          "<File>" +
            "<LocalPath>{6}</LocalPath>" +
            "<RemotePath>{7}</RemotePath>" +
            "<Backup>{8}</Backup>" +
            "<ScheduledForBackup>{9}</ScheduledForBackup>" +
            "<Result>{10}</Result>" +
            "<Size>{11}</Size>" +
            "<CompressedSize>{12}</CompressedSize>" +
            "<Compressed>{13}</Compressed>" +
            "<StartTime>{14}</StartTime>" +
            "<EndTime>{15}</EndTime>" +
            "<ErrorMessage>{16}</ErrorMessage>" +
          "</File>" +
          "<File>" +
            "<LocalPath>{17}</LocalPath>" +
            "<RemotePath>{18}</RemotePath>" +
            "<Backup>{19}</Backup>" +
            "<ScheduledForBackup>{20}</ScheduledForBackup>" +
            "<Result>{21}</Result>" +
            "<Size>{22}</Size>" +
            "<CompressedSize>{23}</CompressedSize>" +
            "<Compressed>{24}</Compressed>" +
            "<StartTime>{25}</StartTime>" +
            "<EndTime>{26}</EndTime>" +
            "<ErrorMessage>{27}</ErrorMessage>" +
          "</File>" +
          "<File>" +
            "<LocalPath>{28}</LocalPath>" +
            "<RemotePath>{29}</RemotePath>" +
            "<Backup>{30}</Backup>" +
            "<ScheduledForBackup>{31}</ScheduledForBackup>" +
            "<Result>{32}</Result>" +
            "<Size>{33}</Size>" +
            "<CompressedSize>{34}</CompressedSize>" +
            "<Compressed>{35}</Compressed>" +
            "<StartTime>{36}</StartTime>" +
            "<EndTime>{37}</EndTime>" +
            "<ErrorMessage>{38}</ErrorMessage>" +
          "</File>" +
        "</Message>";

            Guid msgID = Guid.NewGuid();
            string cltID = Guid.NewGuid().ToString();
            DateTime sentDate = DateTime.Now.ToUniversalTime();
            Version expectedVersion = new Version("1.0.1406.29");

            object[] valuesSets1 = new object[] { msgID, cltID, "1.0.1406.29", sentDate,"AD015", @"AD\Courtel", @"C:\Users\Courtel.ad\AppData\Local\Microsoft\Outlook\Archive1.pst", @"\\192.168.0.250\Pst Files\Courtel\Archive1.pst",
            "True","True","0","7966201280","4012151441","True","15/03/2015 04:19:55","15/03/2015 06:27:33","",
            @"C:\Users\Courtel.ad\AppData\Local\Microsoft\Outlook\Archive2.pst", @"\\192.168.0.250\Pst Files\Courtel\Archive2.pst",
            "True","True","0","956325795","624567895","True","15/03/2015 06:29:55","15/03/2015 07:01:33","An error occurred while writing to remote path",
            @"C:\Users\Courtel.ad\AppData\Local\Microsoft\Outlook\Archive3.pst", @"\\192.168.0.250\Pst Files\Courtel\Archive1.pst",
            "True","True","0","861235420","45236585340","True","15/03/2015 07:03:55","15/03/2015 07:27:33","An error occurred while writing to remote path"};

            ClientMessage clientMsg = new ClientMessage(String.Format(xmlMsg, valuesSets1));

            Assert.AreEqual(cltID, clientMsg.ClientID, "ClientID is not properly initialized.");
            Assert.AreEqual("AD015", clientMsg.ComputerName, "ComputerName is not properly initialized.");
            Assert.AreEqual(@"AD\Courtel", clientMsg.UserName, "UserName is not properly initialized.");
            Assert.AreEqual(expectedVersion, clientMsg.ClientVersion, "ClientVersion is not properly initialized.");
            Assert.AreEqual(sentDate.ToString(), clientMsg.SentDate.ToString(), "SentDate is not properly initialized.");
            Assert.AreEqual(clientMsg.PstFiles.Count, 3, "PstFile is not properly initialized");

            ClientMessage nullClientMsg = new ClientMessage(null);

            Assert.IsTrue(nullClientMsg != null);
        }
    }
}
